<template>
  <div class="search-boxing">
    <div class="button">
      <div class="city" @click="goto(1)">
        <span>{{currentCity.label}}</span>
        <van-icon name="arrow-down" size="12px"></van-icon>
      </div>
      <div class="search" @click="goto(2)">
        <van-icon name="search" size="24px"></van-icon>
        <span>请输入地区或地址</span>
      </div>
    </div>
    <i class="iconfont icon-map" @click="goto(3)"></i>
  </div>
</template>

<script>
import { getCity } from "../utils/index.js";
export default {
  data() {
    return {
      currentCity: {}
    };
  },
  methods: {
    goto(item) {
      switch (item) {
        case 1:
          this.$router.push("/citylist");
          break;
        case 2:
          this.$router.push("/search");
          break;
        case 3:
          this.$router.push("/map");
          break;
      }
    }
  },
  async created() {
    const res = await getCity();
    this.currentCity = res;
  }
};
</script>

<style lang="less" scoped>
.search-boxing {
  width: 100%;
  position: relative;
  padding-left: 20px;
  height: 40px;
  .button {
    display: flex;
    width: 300px;
    height: 40px;
    line-height: 40px;
    background: rgb(255, 255, 255);
    border-radius: 5px;
    box-shadow: 0px 0px 1px 1px rgba(138, 134, 134, 0.3);
    .city {
      padding-left: 10px;
      margin-right: 5px;
      span {
        margin-right: 3px;
      }
    }
    .search {
      padding-left: 40px;
      position: relative;
      font-size: 12px;
      color: #cccccc;
      flex-grow: 1;
      .van-icon {
        position: absolute;
        left: 13px;
        top: 8px;
      }
    }
  }
  .iconfont {
    position: absolute;
    font-size: 30px;
    top: 5px;
    right: 12px;
  }
}
</style>
